/**
 * 	@author btan
 * 	@email: btan@tma.com.vn - anbtan@gmail.com
 */
package com.vital.mshopping;

import java.util.List;


import android.content.Context;

import com.vital.dao.Bookmark;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class BookmarkAdapter extends ArrayAdapter<Bookmark>{
	Context mContext;
	int tvResourceId;
	List<Bookmark> bookmarks;
	
	public BookmarkAdapter(Context context, int textViewResourceId,
			List<Bookmark> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		mContext = context;
		tvResourceId = textViewResourceId;
		bookmarks = objects;
		
		if (bookmarks.isEmpty()) {
			Toast.makeText(mContext, "No data display", Toast.LENGTH_LONG).show();
		}
	}

	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = convertView;
		
		if (v == null) {
			LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = li.inflate(tvResourceId, null);
		}
		Bookmark bookmark = bookmarks.get(position);
		if (bookmark != null) {
			// Fill information of locations
			TextView tvTitle = (TextView)v.findViewById(R.id.tvTitle);
			TextView tvAddress = (TextView)v.findViewById(R.id.tvAddress);
			
			
			tvTitle.setText(bookmark.getName().toString());
			tvAddress.setText(bookmark.getAddress().toString());
			
		} 
		
		return v;
	}

	
	
	
	

}
